/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.BugRS.buz;

import com.aptech.BugRS.dao.ResponseDAO;
import com.aptech.BugRS.enity.ResponseDTO;
import java.util.ArrayList;

/**
 *
 * @author KISS
 */
public class ResponseBUZ {

    ResponseDAO dao = null;
    private String lastError = "";

    public ResponseBUZ() {
        dao = new ResponseDAO();
    }

    /**
     * Add a new Response
     * @param response
     * @return boolean
     */
    public boolean create(ResponseDTO res) {
        if (!res.Validate()) {
            //this.lastError = history.getValidateDescription();
            setLastError("E_Response error");
            return false;
        }
        if (dao.isExits(res)) {
            this.setLastError(dao.getLastError());
            return false;
        }
        if (!dao.Create(res)) {
            this.setLastError(dao.getLastError());
            return false;
        }
        this.setLastError(dao.getLastError());
        return true;
    }

    /**
     * Read all Response
     * @return list of Response
     */
    public ArrayList<ResponseDTO> findByAll() {
        return dao.ReadByAll();
    }

//    public ArrayList<E_Response> findByID() {
//        return dao.ReadByID();
//    }
    /**
     * Update Response
     * @param response
     * @return boolean
     */
    public boolean store(ResponseDTO res) {
        if (!res.Validate()) {
            setLastError("Entity Response Error");
            return false;
        }
        if (!dao.Update(res)) {
            this.lastError = dao.getLastError();
            return false;
        }
        setLastError(dao.getLastError());
        return true;
    }

    /**
     * @return the lastError
     */
    public String getLastError() {
        return lastError;
    }

    /**
     * @param lastError the lastError to set
     */
    public void setLastError(String lastError) {
        this.lastError = lastError;
    }
}
